CLEA
DR='N:'
F1='PUR_DRUG'
F2='PUR_DISP'
F3='PUR_TEMP'
DO ADDRESSC
DSP1=SAVESCREEN(24,0,24,79)
SET COLO TO R+/B+*
@ 24,02 SAY 'PLEASE WAIT ...'
SET COLO TO W+/B+
SUPPCOD=SPACE(4)
ORDNBER=SPACE(4)
SELE 1
SET EXCLU OFF
USE &DR&F1
SELE 2
SET EXCLU OFF
USE &DR&F2
SELE 3
SET EXCLU OFF
USE &DR&F3
IF NET_USE('&DR&F3',.T.,'3',10)
   ZAP
ENDIF
SET EXCLU OFF
SELE 1
GO TOP
DO WHILE .NOT. EOF()
   SELE 3
   IF FIL_LOCK(0)
      APPEND BLANK
   ENDIF
   IF REC_LOCK(0)
      REPL D_NAME WITH A->DRUG_NAME,      D_TYPE WITH A->DRUG_TYPE
      REPL D_UNIT WITH A->DRUG_UNIT,      D_QANT WITH A->DRUG_QANT
      REPL BUY_UNIT WITH A->BUY_UNIT,     D_CODE WITH A->DRUG_CODE
      REPL SUPP_NAME WITH A->SUPP_NAME,   SUPP_CODE WITH A->SUPP_CODE
      REPL ORDER_NBER WITH A->ORDER_NBER, U_PR_PURCH WITH A->U_PR_PURCH
      REPL QANT_PURCH WITH A->QANT_PURCH, VALU_PURCH WITH A->VALU_PURCH
      REPL DISC_PURCH WITH A->DISC_PURCH, NET_PURCH WITH A->NET_PURCH
      REPL ORDR_PRINT WITH A->ORDR_PRINT, DATE_PURCH WITH A->DATE_PURCH
*      REPL AEA_COMP WITH FREEP
   ENDIF
   UNLOCK
   SELE 1
   SKIP
ENDDO
SELE 2
GO TOP
DO WHILE .NOT. EOF()
   SELE 3
   IF FIL_LOCK(0)
      APPEND BLANK
   ENDIF
   IF REC_LOCK(0)
      REPL D_NAME WITH B->DISP_NAME,      D_TYPE WITH B->DISP_TYPE
      REPL D_UNIT WITH B->DISP_UNIT,      D_QANT WITH B->DISP_QANT
      REPL BUY_UNIT WITH B->BUY_UNIT,     D_CODE WITH B->DISP_CODE
      REPL SUPP_NAME WITH B->SUPP_NAME,   SUPP_CODE WITH B->SUPP_CODE
      REPL ORDER_NBER WITH B->ORDER_NBER, U_PR_PURCH WITH B->U_PR_PURCH
      REPL QANT_PURCH WITH B->QANT_PURCH, VALU_PURCH WITH B->VALU_PURCH
      REPL DISC_PURCH WITH B->DISC_PURCH, NET_PURCH WITH B->NET_PURCH
      REPL ORDR_PRINT WITH B->ORDR_PRINT
*      REPL AEA_COMP WITH FREEP
   ENDIF
   UNLOCK
   SELE 2
   SKIP
ENDDO
CLOSE DATA
CLOSE INDEX
F1='PUR_TEMP'
F2='SUPPLIER'
SET EXCLU OFF
USE &DR&F1
INDEX ON ORDER_NBER TO &DR&F1
CLOSE DATA
CLOSE INDEX
SET EXCLU OFF
SELE 1
USE &DR&F1 INDEX &DR&F1
SET EXCLU OFF
SELE 2
USE &DR&F2
RESTSCREEN(24,0,24,79,DSP1)
KLR='N'
DO SET_DEV
IF KLR='Y'
   SET EXCLU OFF
   CLOSE DATA
   CLOSE INDEX
   RETURN
ENDIF
   SET COLO TO W+/B+
   DO ADDRESSC
   @  5,  3  TO  7, 33    DOUBLE
   @  6,  5  SAY "PRINT RECAP. PURCHASE ORDER"
   KLR='N'
   br=100
   fl=0
   hl=0
   ttl=0
   store 0 to ttl1,ttl2,ttl3,ttl4,ttl5
   set devi to print
   @ 0,0 say chr(18) pict 'x'
   @ 0,0 SAY CHR(27)+CHR(77)
SELE 1
GO TOP
DO WHILE .NOT. EOF()
    IF ORDER_NBER=0
       SKIP
       LOOP
    ENDIF
    if br>57
     if fl>0
       eject
     else
       fl=1
     endif
     cl=50
     hl=hl+1
     @  2, 44 say 'RECAPITULATION OF PURCHASE ORDER'
     @  3, 44 SAY '--------------------------------'
     @  4, 122 say 'PAGE : '
     @  4, 129 say hl pict '999'
     @  5, 117 say 'DATE : '
     @  5, 124 say DATE()
     @  6,  0 say repl('=',132)
     @  7,  0 say 'ORDER'
     @  7,  7 say 'DATE'
     @  7, 17 say 'SUPPLIER'
     @  7, 27 say 'SUPPLIER NAME'
     @  7, 54 say '  TOTAL VALUE'
     @  7, 69 say '     P.P.N.'
     @  7, 82 SAY '  TOTAL VALUE'
     @  7, 97 SAY 'DRUG/DISPOSABLE NAME'
     @  7,124 SAY 'QUANTITY'
     @  8, 17 SAY 'CODE'
     @  8, 54 SAY '   BEFORE TAX'
     @  8, 82 SAY '    AFTER TAX'
     @  9,0 say repl('-',132)
     br=9
    endif
    br=br+1
      ORDNUM=ORDER_NBER
      DATPUR=DATE_PURCH
      CODSUP=SUPP_CODE
      NAMSUP=SUPP_NAME
      TTL=0
      SEEK ORDNUM
      DO WHILE ORDER_NBER=ORDNUM .AND. .NOT. EOF()
         TTL=TTL+NET_PURCH
         SKIP
      ENDDO
      MPPN=.F.
      SELE 2
      LOCATE FOR SUPP_CODE=CODSUP
      IF FOUND()
         SUPPCOD=SUPP_CODE
         SUPPNAM=SUPP_NAME
         SUPPADD1=SUPP_ADD1
         SUPPADD2=SUPP_ADD2
         SUPPCITY=SUPP_CITY
         SUPPCOUNT=SUPP_COUNT
         SUPPTEL=SUPP_TEL1
         SUPPFAX=SUPP_FAX
         SUPPTELEX=SUPP_TELEX
         CONPER=CONTACT_P
         MPPN=PPN
         PAYTERM=TERM_PAYMT
      ENDIF
      IF MPPN=.T.
         VALPPN=10/100*TTL
      ELSE
         VALPPN=0
      ENDIF
      GRNTTL=TTL+VALPPN
      @ BR, 0 SAY ORDNUM
      @ BR, 7 SAY DATPUR
      @ BR,17 SAY CODSUP
      @ BR,27 SAY NAMSUP
      DO SAYG WITH  BR,54,TTL,'99,999,999.99','9,999,999,999'
      DO SAYG WITH  BR,69,VALPPN,'99,999,999.99','9,999,999,999'
      DO SAYG WITH  BR,82,GRNTTL,'99,999,999.99','9,999,999,999'
      TTL1=TTL1+TTL
      TTL2=TTL2+VALPPN
      TTL3=TTL3+GRNTTL
      SELE 1
      SEEK ORDNUM
      DO WHILE ORDER_NBER=ORDNUM .AND. .NOT. EOF()
         NMPH=SUBS(ALLTRIM(D_NAME)+' '+ALLTRIM(D_TYPE)+' '+ALLTRIM(D_QANT)+' '+ALLTRIM(D_UNIT),1,25)
         @ BR,97 SAY NMPH
         @ BR,127 SAY QANT_PURCH PICT '9,999'
         BR=BR+1
         SKIP
      ENDDO

ENDDO
BR=BR+1
@ BR,0 SAY REPL('-',132)
BR=BR+1
DO SAYG WITH BR,54,TTL1,'99,999,999.99','9,999,999,999'
DO SAYG WITH BR,69,TTL2,'99,999,999.99','9,999,999,999'
DO SAYG WITH BR,82,TTL3,'99,999,999.99','9,999,999,999'

BR=BR+1
@ BR,0 SAY REPL('=',132)
EJECT
@ 0,0 SAY CHR(18) PICT 'X'
SET DEVI TO SCREEN
CLOSE DATA
CLOSE INDEX
RETURN


